from sanic.views import HTTPMethodView
from sanic.response import text,json
import time
from processing.other_func import ProToken,Sercret_all,Serialization,Random_id,date_format
import json as jn
import re
from processing.Sql_DataFrom import ProJosn
class forbiddenWhite(HTTPMethodView):  # 禁用用户

    def __init__(self):
        self.data = ''

    async def post(self, request):
        db = request.app.ctx.db
        data = request.json
        html_data = data
        client_ip = request.ip
        try:

            find_sql = """
                select user_id from a_users where user_id=%s 
            """
            data = db.find_one(find_sql,(html_data['user_id']))
            if data:
                insert_sql = """
                    insert into white_list(user_id,white_ip,status,create_time ) VALUES (%s,%s,%s,now())
                """
                db.insert(insert_sql,(html_data['user_id'],client_ip,'normal'))

                return json({'code':200, 'message':"禁用成功！"})
            else:
                return json({'code': 201, 'message': "未查到该用户！"})
        except Exception as error:

            error_sql = 'insert into error_log(visit_ip,error_path,error_content,create_time ) VALUES (%s,%s,%s,now())'
            db.insert(error_sql, (client_ip, '/login', error))

            return json({'code':500, 'message':"后端代码出错！"})